package hihocoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;

/**
 * 
 */

/**
 * @author zhongfang
 *
 */
public class 国庆出游 {

	static class Vertex{
		public Vertex(int i) {
			this.index=i;
		}
		int index;
		boolean isVisted=false;
		ArrayList<Vertex> neibors=new ArrayList<>();
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int T=scanner.nextInt();
		while (T-->0) {
			int n=scanner.nextInt();//城市数目
			HashMap<Integer,Vertex> set=new HashMap<>(n);//点的集合
			for(int i=0;i<n-1;i++){
				int a=scanner.nextInt();
				int b=scanner.nextInt();
				
				Vertex curVert,nextVert;
				if(set.containsKey(a)){
					curVert=set.get(a);
				}else {
					curVert=new Vertex(a);
					set.put(a, curVert);
				}
				if(set.containsKey(b)){
					nextVert=set.get(b);
				}else {
					nextVert=new Vertex(b);
					set.put(b, nextVert);
				}
				curVert.neibors.add(nextVert);
//				nextVert.neibors.add(curVert);//假设前一个都是父节点，后一个都是子节点
			}
			int m=scanner.nextInt();
			ArrayList<Integer> mArrayList=new ArrayList<>(m);
			while (m-->0) {
				mArrayList.add(scanner.nextInt());
			}
			Vertex firstVert=set.get(1);//出发点
			boolean flat=ableWithSeq(mArrayList,firstVert,set.values())!=null;
			if(flat){
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}
		}
	}
	private static ArrayList<Integer> ableWithSeq(ArrayList<Integer> mArrayList, Vertex firstVert, Collection<Vertex> values) {
		ArrayList<Integer> thisList=new ArrayList<>();
		boolean thisCotain=mArrayList.contains(firstVert.index);
		if(thisCotain){
			thisList.add(firstVert.index);
		}
		ArrayList<Integer> leftList=new ArrayList<>();
		ArrayList<Integer> rightList=new ArrayList<>();
		if(firstVert.neibors.size()>0){
			leftList=ableWithSeq(mArrayList, firstVert.neibors.get(0), values);
			if(leftList==null){
				return null;//用null标记出错
			}
			if(firstVert.neibors.size()>1){
				rightList=ableWithSeq(mArrayList, firstVert.neibors.get(1), values);
				if(rightList==null){
					return null;//用null标记出错
				}
			}
		}
		//检查mArray中是否当前结点都在left和right的前面
		if(thisCotain){
			if(leftList.size()!=0&&!isBefore(firstVert.index,leftList,mArrayList)){
				//有错误
				return null;
			}
			if(rightList.size()!=0&&!isBefore(firstVert.index,rightList,mArrayList)){
				return null;
			}
		}
		int res=leftBeforeRight(leftList,rightList,mArrayList);
		if(res==-1){
			return null;
		}
		if(res==1){
			thisList.addAll(leftList);
			thisList.addAll(rightList);
		}else {
			thisList.addAll(rightList);
			thisList.addAll(leftList);
		}
		return thisList;
	}
	private static int leftBeforeRight(ArrayList<Integer> leftList, ArrayList<Integer> rightList,
			ArrayList<Integer> mArrayList) {
		if(leftList.size()==0||rightList.size()==0){
			return 1;
		}
		int i=0,leftIndex=0,rightIndex=0;
		while (mArrayList.get(i)!=leftList.get(0)&&mArrayList.get(i)!=rightList.get(0)) {
			i++;
		}
		if(mArrayList.get(i)==leftList.get(leftIndex)){//左边列表先开始
			while (leftIndex<leftList.size()) {
				if(mArrayList.get(i)!=leftList.get(leftIndex)){
					return -1;
				}
				i++;
				leftIndex++;
			}
			if(mArrayList.get(i)!=rightList.get(0)){
				return -1;
			}
			while (rightIndex<rightList.size()) {
				if(mArrayList.get(i)!=rightList.get(rightIndex)){
					return -1;
				}
				i++;
				rightIndex++;
			}
			return 1;
		}else {//右边列表在前面
			while (rightIndex<rightList.size()) {
				if(mArrayList.get(i)!=rightList.get(rightIndex)){
					return -1;
				}
				i++;
				rightIndex++;
			}
			
			if(mArrayList.get(i)!=leftList.get(0)){
				return -1;
			}
			while (leftIndex<leftList.size()) {
				if(mArrayList.get(i)!=leftList.get(leftIndex)){
					return -1;
				}
				i++;
				leftIndex++;
			}
			return 0;
		}
	}
	/***
	 * 
	 * @param index 父节点坐标
	 * @param childList
	 * @param mArrayList
	 * @return
	 */
	private static boolean isBefore(int index, ArrayList<Integer> childList, ArrayList<Integer> mArrayList) {
		int childIndex=0,mIndex=0;
		while (childList.get(childIndex)!=mArrayList.get(mIndex)&&mArrayList.get(mIndex)!=index) {
			mIndex++;
		}
		if(mArrayList.get(mIndex)!=index){
			return false;
		}else {
			return true;
		}
	}

}
